package models

import (
	"github.com/liangchao/blogo/src/common/global"
	"time"
)

type Message struct {
	Id int `gorm:"id primaryKey" json:"id"`
	Name string `gorm:"name" json:"name" binding:"required"`
	Email string `gorm:"email" json:"email" binding:"required"`
	Phone string `gorm:"phone" json:"phone" binding:"required"`
	Message string `gorm:"message" json:"message" binding:"required"`
	IsDeleted int `gorm:"is_deleted" json:"is_deleted"`
	CreateTime *time.Time `gorm:"create_time" json:"create_time"`
	CreateTimeStr string `gorm:"-" json:"create_time_str"`
	UpdateTime *time.Time `gorm:"update_time" json:"update_time"`
	UpdateTimeStr string `gorm:"-" json:"update_time_str"`
}

// TableName 表名
func (*Message) TableName() string {
	return "message"
}

// AddMessage 添加消息
func (m *Message) AddMessage() (err error) {
	err = global.DB.Select("name", "email", "phone", "message").Create(m).Error
	return
}
